package homework711;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

import javax.naming.Name;

//1:服务器上存有多个用户对象（包括用户和密码），客户端通过socket登录，如果成功，输出欢迎信息，失败给出提示。

public class work1client {
	public static void main(String[] args) {
		Socket s = null;
		FileOutputStream fo = null;
		Scanner sc = new Scanner(System.in);
		try {
			s = new Socket("localhost", 6666);
			OutputStream out = s.getOutputStream();
			ObjectOutputStream oot = new ObjectOutputStream(out);
			System.out.println("请输入用户名");
			Object name = sc.next();
			System.out.println("请输入密码");
			Object pwd = sc.next();

			// Map<String, Object> map = new HashMap<>();
			// Map a = (Map) map.put(name, pwd);
			oot.writeObject(name);
			oot.writeObject(pwd);
			InputStream in = s.getInputStream();
			ObjectInputStream oin = new ObjectInputStream(in);
			String str = (String) oin.readObject();
			System.out.println(str);

			oot.writeObject("已收到");
			oin.close();
			oot.close();
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} finally {
			try {
				if (s != null)
					s.close();

			} catch (IOException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}

	}

}
